package database

import (
	// "fmt"
	"gorm.io/gorm"
)

type Category struct {
	ID       int64  `gorm:"column:id"` // 主键
	Category string `gorm:"column:category"`
	Comment  string `gorm:"column:comment"`
}

type Item struct {
	ID int64 `gorm:"column:id"` // 主键
	Title string `gorm:"column:title"`
	Price string `gorm:"column:price"`
	// Category Category `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	Category int64 `gorm:"column:category"`
	Detail   string   `gorm:"foreignKey:detail"`
}

func (c Category) TableName() string {
	return "category"
}

func (i Item) TableName() string {
	return "item"
}

func Insert() {}

func Delete() {}

func Update() {}

func QueryItem(db *gorm.DB) []Item {
	sql := "SELECT * FROM `item` LIMIT 10"
	results := make([]Item, 10)
	db.Raw(sql).Scan(&results)
	// fmt.Println(results[0])
	return results
}

func QueryCategory(db *gorm.DB) []Category {
	sql := "SELECT * FROM `category` LIMIT 10"
	results := make([]Category, 10)
	db.Raw(sql).Scan(&results)
	// fmt.Println(results[0])
	return results
}